package com.freak.wanandroid.model.login.login;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;

import com.freak.httpmanager.BaseViewModel;
import com.freak.httpmanager.callback.ApiCallback;
import com.freak.httpmanager.callback.SubscriberCallBack;
import com.freak.wanandroid.bean.LoginBean;

/**
 * Created by 74099 on 2018/8/29.
 */

public class LoginViewModel extends BaseViewModel<LoginRepository> {
    protected MutableLiveData<LoginBean> mDoLogin = new MutableLiveData<>();
    protected MutableLiveData<String> mDoLoginError = new MutableLiveData<>();

    public LoginViewModel(@NonNull Application application) {
        super(application);
    }

    public void doLogin(String username, String password) {
        mRepository.doLogin(username, password, new SubscriberCallBack<>(new ApiCallback<LoginBean>() {
            @Override
            public void onSuccess(LoginBean model) {
                mDoLogin.postValue(model);
            }

            @Override
            public void onFailure(String msg) {
                mDoLoginError.postValue(msg);
            }
        }));
    }
}
